﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="QLSanPham.aspx.cs" Inherits="WebBanThuoc.admin.QLSanPham" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Quản Lý Sản Phẩm</title>
    <link rel="shortcut icon" href="../img/admin.ico" />
        <script src="../js/jquery-1.7.2.js" type="text/javascript"></script>
        <script src="../js/jquery.keyfilter.js" type="text/javascript"></script>
        <script src="../js/jquery.maskedinput.js" type="text/javascript"></script>
        <script src="../js/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
        <script src="../js/thai.js" type="text/javascript"></script>
        <script src="../js/colResizable-1.3.min.js" type="text/javascript"></script>
        <script src="../ckeditor/ckeditor.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="../style/static.css"/>
        <link rel="stylesheet" type="text/css" href="../style/dangnhap_btn.css"/>
        <link type="text/css" href="../style/flick/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
        <style type="text/css">
            .f_span-74
            {
                width:1100px; 
                float:none;		
                padding: 20px;
            }
            input, textarea {
                -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
                -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
                -webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
                -moz-transition: border linear 0.2s, box-shadow linear 0.2s;
                -ms-transition: border linear 0.2s, box-shadow linear 0.2s;
                -o-transition: border linear 0.2s, box-shadow linear 0.2s;
                transition: border linear 0.2s, box-shadow linear 0.2s;
                line-height: 18px;
                color: #555;
                border: 1px solid #CCC;
                -webkit-border-radius: 3px;
                border-radius: 3px;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
                font-size: 15px;
                height: 20px;
                font-weight: normal;
                width: 358px;
            }
            .inputEmail
            {
                height:24px;
            }
            .thai_font
            {
                font-family:"Helvetica Neue", Helvetica, Arial, sans-serif	
            }
            .thai_font_DN
            {
                font-size:30px;
                font-weight:bold;
                padding:10px 0px 30px;		
                color:#0088CC;
                width:820px;
                float:left;
            }
            .thai_font_lable
            {
                font-size:14px;
                font-weight:bold;
                padding-bottom:3px;
                width: 180px;
                margin-top:5px;
            }
            .thai_font_lable_right
            {
                font-size:14px;
                font-weight:bold;
                padding-bottom:3px;
                width: 140px;
                margin-top:5px;
            }
            div{
                float:left;	
            }
        </style>       
        <script language="javascript" type="text/javascript">
                    
            <%if (Session["page_QLSanPham_dataSP"] == null)
                {%>
                var coDT = false;
            <%}  else{%>
                var coDT = true;
            <%} %>
            
                function CheckRegisterFormEmail(e) {
                    var strEmail = $(e).val();
    
                    regem = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
                    return regem.test(strEmail)
   
                }
                function ModifyProduct(){
                    if($.trim($('#MaSanPham').val()) == ""){
                        alert("Bạn chưa nhập Mã sản phẩm.");
                        $('#MaSanPham').focus();
                        return false;
                    }
                    if(coDT==false){
                        alert("Mã sản phẩm này không tồn tại trong Cơ sở dữ liệu.");
                        $('#MaSanPham').focus();
                        return false;
                    }
				    if($.trim($('#TenSanPham').val()) == ""){
                        alert("Bạn chưa nhập Tên sản phẩm.");
                        $('#TenSanPham').focus();
                        return false;
                    }
                }

                function DeleteProduct(){
                    if($.trim($('#MaSanPham').val()) == ""){
                        alert("Bạn chưa nhập Mã sản phẩm.");
                        $('#MaSanPham').focus();
                        return false;
                    }
                    if(coDT==false){
                        alert("Mã sản phẩm này không tồn tại trong Cơ sở dữ liệu.");
                        $('#MaSanPham').focus();
                        return false;
                    }
                    
				    if(!confirm("Nếu xóa Sản phẩm, tất các các thông tin, hình ảnh, \nhóa đơn giao dịch,... liên quan tới sản phẩm này đều bị xóa.\n\nBạn có muốn xóa sản phẩm không ?")){                                               
                        return false;
                    }
                }
			
                function CheckLoginForm_Search(){
                    if($.trim($('#MaSanPham').val()) == ""){
                        alert("Bạn chưa nhập Mã sản phẩm.");
                        $('#MaSanPham').focus();
                        return false;
                    }                
				
                }
			
                function AddProduct(){
                    if($.trim($('#MaSanPham').val()) != ""){
                        alert("Để thêm sản phẩm mới, bạn không được nhập giá trị vào ô Mã sản phẩm.");
                        $('#MaSanPham').focus();
                        return false;
                    }
				    if($.trim($('#TenSanPham').val()) == ""){
                        alert("Bạn chưa nhập Tên sản phẩm.");
                        $('#TenSanPham').focus();
                        return false;
                    }
                    return true;
				
                }
			
                function searchSP(){
                    var data = $('#MaSanPham').val();
                    if($.trim(data)==''){
                        alert('Nếu Mã sản phẩm bỏ trống, tức là bạn đang dùng tính năng thêm mới.');
                        $('#div_spMoi').show(500);
                        $('#MaSanPham').focus();
                        //return false;
                    } else{
                        $('#frm_TimSP').submit();
                        //return true;
                    }
                }
                $(function(){
  			        
                    setTimeout(function () {
                        $('#MaSanPham').focus();
                    }, 700);

                    //$('#NgayTao').mask('99/99/9999');
                    //$('#NgaySua').mask('99/99/9999');

                    $("#GiaBan").change(function(){
                        if($(this).val() == ""){
                            $(this).val("0");
                        }
                    });
                    $("#GiaDaGiam").change(function(){
                        if($(this).val() == ""){
                            $(this).val("0");
                        }
                    });                    
                    $('#KhuyenMai').keypress(function(e){
                        var code = (e.keyCode? e.keyCode:e.which);
                        if(code == 13 || code == 10){
                            return false;	
                        }
                        var rsk = setMaxLength(this,499);
                        if(rsk == false){
                            alert("Không được nhập quá 500 kí tự. Số kí tự hiện giờ là " + this.value.length);
                        }
                        if(code==8 || code==38||code==40||code==37||code==39||code==17||code==18||code==9||code==36||code==35||code==46||code==33||code==34||code==144||code==145){
                            return true;
                        }
                        return rsk;
                    });                                       
			        
                    
                });
                function setMaxLength(Object, MaxLen)
                {
                    return (Object.value.length <= MaxLen);
                }
                function clearAllInput(){
                    $('#frm_TimSP').find(':input').each(function(){
                        switch(this.type){
                            case 'password':
                            case 'select-multiple':
                            case 'select-one':
                            case 'text':
                            case 'textarea':
                                //if($(this).attr('name')!='MaSanPham'){
                                $(this).val('');
                                //}
                                break;
                            case 'checkbox':
                            case 'radio':
                                this.checked = false;
                                break;
                            case 'file':
                                //this.replaceWith('<input type="file" name="HinhAnh" id="HinhAnh"  style="width:227px" />');
                                $(this).val('');
                                break;
                        }
                    });
                    CKEDITOR.instances["ThanhPhan"].setData("");
                    CKEDITOR.instances["CongDung"].setData("");
                    CKEDITOR.instances["CachDung"].setData("");
                    coDT = false;
                }            

             <%if (Session["page_QLSanPham_msgSucessFunc"] != null)
                {%>
                alert("<%=Session["page_QLSanPham_msgSucessFunc"] %>");
            <%} %>
            
        </script>
</head>
<body>
    <form name="frm_TimSP" id="frm_TimSP" method="post" runat="server" >
        <% WebBanThuoc.DTO.SanPham objSP = (WebBanThuoc.DTO.SanPham)Session["page_QLSanPham_dataSP"]; %>
            <div style="float: none; margin: 20px;" class="f_span-74">
                <div style="width:100%;text-align:center">
                    <div class="thai_font thai_font_DN">QUẢN LÝ SẢN PHẨM</div>
                </div>
                <div style="width:100%;text-align:center">&nbsp;</div>
                <div style="width:810px;text-align:left">
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Mã sản phẩm:</div>
                        <div style="float:left;width:20px" class="thai_font_lable">SP</div>
                        <input type="text" name="MaSanPham" id="MaSanPham" autocomplete="off" class="mask-pint"  maxlength="8"  style="width:100px;float:left" onchange="searchSP()" value="<%=Request.Params["btn_Xoa"] == null?Request.Params["MaSanPham"]:""  %>"/>
                        <div style="float:left;color:#666;width:175px; margin-left:15px; font-size:11px; margin-top:0" class="thai_font_lable">Chỉ nhập vào khi sửa hoặc xóa Sản phẩm.</div>
                    </div>                    
                    <div style="width:100%;text-align:left; margin-bottom:10px;" id="div_spMoi">
                        <div style="width:180px;">&nbsp;</div>                            
                        <div title="Mã sản phẩm mới tiếp theo nếu bạn tạo Sản Phẩm mới" style="color:Gray; font-size:12px;width: 300px; margin-left:20px;font-weight: bold;cursor:pointer;"><%=Session["page_QLSanPham_MaSanPham_Moi"]%></div>                            
                    </div>                    
                    <% if (objSP == null && Request.Params["MaSanPham"] != null && Request.Params["MaSanPham"] != "" && Request.Params["btn_Xoa"] == null)
                       { %>
                    <div style="width:100%;text-align:left; margin-bottom:10px;">
                        <div style="width:180px;">&nbsp;</div>                            
                        <div style="color:#F00; font-size:12px;width: 320px;">Không tồn tại Mã sản phẩm " <%=Request.Params["MaSanPham"]%> " trong Cơ sở dữ liệu 'Sản phẩm'.</div>                            
                    </div>
                    <%} %>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Tên sản phẩm:</div>
                        <input type="text" name="TenSanPham" id="TenSanPham" autocomplete="off" maxlength="100"  style="width:300px"  value="<%=objSP!=null?objSP.TenSanPham:"" %>" />
                    </div>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Hãng sản xuất:</div>
                        <select name="MaNhaSanXuat" style="width:310px;">
                            <% System.Collections.Generic.List<WebBanThuoc.DTO.NhaSanXuat> dataListNSX = Session["page_QLSanPham_dataListNSX"] as System.Collections.Generic.List<WebBanThuoc.DTO.NhaSanXuat>;
                               for (int i = 0; i < dataListNSX.Count; i++)
                               {%>
                                <option value="<%=dataListNSX[i].MaNhaSanXuat %>"  <%=(objSP == null && i == 0) ? "selected='selected'" : ((objSP != null && dataListNSX[i].MaNhaSanXuat == objSP.MaNhaSanXuat) ? "selected='selected'" : "")%> ><%=dataListNSX[i].TenNhaSanXuat + " - " + dataListNSX[i].MaNhaSanXuat%></option>
                            <%} %>
                        </select>
                    </div>

                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Loại sản phẩm:</div>
                        <select name="MaLoaiSanPham" style="width:310px;">
                            <% System.Collections.Generic.List<WebBanThuoc.DTO.LoaiSanPham> dataListLSP = Session["page_QLSanPham_dataListLSP"] as System.Collections.Generic.List<WebBanThuoc.DTO.LoaiSanPham>;
                                for (int i = 0; i < dataListLSP.Count; i++)
                               {%>
                                <option value="<%=dataListLSP[i].MaLoaiSanPham %>"  <%=(objSP == null && i == 0) ? "selected='selected'" : ((objSP != null && dataListLSP[i].MaLoaiSanPham == objSP.MaLoaiSanPham) ? "selected='selected'" : "")%> ><%=dataListLSP[i].TenLoaiSanPham + " - " + dataListLSP[i].MaLoaiSanPham%></option>                                
                            <%} %>
                        </select>
                    </div>

                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Công dụng:</div>
                        <div style="width:625px;text-align:left;margin-bottom: 8px;">                        
                            <CKEditor:CKEditorControl CssClass="div" Height="100px" ID="CongDung" 
                                runat="server" ResizeEnabled="false" Toolbar="Source|-|NewPage|Preview|-|Templates
Cut|Copy|Paste|PasteText|PasteFromWord|-|Print|SpellChecker|Scayt
Form|Checkbox|Radio|TextField|Textarea|Select|Button|ImageButton|HiddenField
Undo|Redo|-|Find|Replace|-|SelectAll|RemoveFormat
/
Bold|Italic|Underline|Strike|-|Subscript|Superscript
NumberedList|BulletedList|-|Outdent|Indent|Blockquote|CreateDiv
Link|Unlink|Anchor
Image|Flash|Table|HorizontalRule|Smiley|SpecialChar|PageBreak|Iframe
JustifyLeft|JustifyCenter|JustifyRight|JustifyBlock
BidiLtr|BidiRtl
/
Styles|Format|Font|FontSize
TextColor|BGColor
Maximize|ShowBlocks|-|About"></CKEditor:CKEditorControl>
                        </div>
                    </div>

                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Thành Phần:</div>
                        <div style="width:625px;text-align:left;margin-bottom: 8px;">                        
                            <CKEditor:CKEditorControl CssClass="div" Height="100px" ID="ThanhPhan" 
                                runat="server" ResizeEnabled="false" Toolbar="Source|-|NewPage|Preview|-|Templates
Cut|Copy|Paste|PasteText|PasteFromWord|-|Print|SpellChecker|Scayt
Form|Checkbox|Radio|TextField|Textarea|Select|Button|ImageButton|HiddenField
Undo|Redo|-|Find|Replace|-|SelectAll|RemoveFormat
/
Bold|Italic|Underline|Strike|-|Subscript|Superscript
NumberedList|BulletedList|-|Outdent|Indent|Blockquote|CreateDiv
Link|Unlink|Anchor
Image|Flash|Table|HorizontalRule|Smiley|SpecialChar|PageBreak|Iframe
JustifyLeft|JustifyCenter|JustifyRight|JustifyBlock
BidiLtr|BidiRtl
/
Styles|Format|Font|FontSize
TextColor|BGColor
Maximize|ShowBlocks|-|About" ></CKEditor:CKEditorControl>
                        </div>
                    </div>                                        

                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Cách Dùng:</div>
                        <div style="width:625px;text-align:left;margin-bottom: 8px;">                        
                            <CKEditor:CKEditorControl CssClass="div" Height="100px" ID="CachDung" 
                                runat="server" ResizeEnabled="false" Toolbar="Source|-|NewPage|Preview|-|Templates
Cut|Copy|Paste|PasteText|PasteFromWord|-|Print|SpellChecker|Scayt
Form|Checkbox|Radio|TextField|Textarea|Select|Button|ImageButton|HiddenField
Undo|Redo|-|Find|Replace|-|SelectAll|RemoveFormat
/
Bold|Italic|Underline|Strike|-|Subscript|Superscript
NumberedList|BulletedList|-|Outdent|Indent|Blockquote|CreateDiv
Link|Unlink|Anchor
Image|Flash|Table|HorizontalRule|Smiley|SpecialChar|PageBreak|Iframe
JustifyLeft|JustifyCenter|JustifyRight|JustifyBlock
BidiLtr|BidiRtl
/
Styles|Format|Font|FontSize
TextColor|BGColor
Maximize|ShowBlocks|-|About" ></CKEditor:CKEditorControl>
                        </div>
                    </div>
                    <%if (objSP != null)
                      { %>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Ngày tạo:</div>
                        <input type="text" name="NgayTao" id="NgayTao" style="width:300px"  value="<%=objSP != null ? objSP.NgayTao.ToString("dd/MM/yyyy HH:mm:ss tt") : ""%>" readonly="readonly" tabindex="-1"/>
                    </div>
                    
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Ngày sửa:</div>
                        <input type="text" name="NgaySua" id="NgaySua" style="width:300px"  value="<%=objSP != null ? objSP.NgaySua.ToString("dd/MM/yyyy HH:mm:ss tt") : ""%>" readonly="readonly" tabindex="-1"/>
                    </div>
                    <%} %>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Giá bán:</div>
                        <input type="text" name="GiaBan" id="GiaBan" autocomplete="off" maxlength="16" class="mask-money"  style="width:300px"  value="<%=objSP!=null?String.Format("{0:#,0.##}",objSP.GiaBan):"" %>"/>
                    </div>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Giá đã giảm:</div>
                        <input type="text" name="GiaDaGiam" id="GiaDaGiam" autocomplete="off" maxlength="16" class="mask-money"  style="width:300px"  value="<%=objSP!=null?String.Format("{0:#,0.##}",objSP.GiaDaGiam):"" %>"/>
                    </div>                   
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Khuyến mãi kèm theo:</div>
                        <textarea cols="10" title="Không quá 500 kí tự" rows="3" id='KhuyenMai' name="KhuyenMai" style="resize:none;width:300px; height:80px;overflow:visible"><%=objSP!=null?objSP.KhuyenMai:"" %></textarea>
                    </div>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Mô Tả:</div>
                        <input type="text" name="MoTa" id="MoTa" autocomplete="off" maxlength="199" style="width:300px"  value="<%=objSP!=null?objSP.MoTa:"" %>"/>
                    </div>
                    <div style="width:100%;text-align:left;height: 35px;">
                        <div style="float:left" class="thai_font_lable">Hàng mới:</div>                        
                        <input type="checkbox" id="IsNew" name="IsNew" <%=objSP != null && objSP.IsNew ? "checked='checked'" : ""%> value="IsNew"/> 
                    </div>
                    <div style="width:100%;text-align:left;height: 35px;">
                        <div style="float:left" class="thai_font_lable">Còn hàng:</div>                        
                        <input type="checkbox" id="CoHang" name="CoHang" value="CoHang" <%=objSP != null && objSP.CoHang ? "checked='checked'" : ""%> />
                    </div>
                    
                    <%if (objSP != null)
                      { %>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Số lượt xem:</div>
                        <input type="text" name="SoLuotXem" id="SoLuotXem"  maxlength="16" class=" mask-pnum"  style="width:300px"  value="<%=objSP!=null?objSP.SoLuotXem.ToString():"" %>" readonly="readonly" tabindex="-1"/>
                    </div>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Đánh giá:</div>
                        <input type="text" name="DanhGia" id="DanhGia"  maxlength="11" class="mask-pint" style="width:300px" value="<%=objSP!=null?objSP.DanhGia.ToString():"" %>" readonly="readonly" tabindex="-1"/>
                    </div>
                    <div style="width:100%;text-align:left">
                        <div style="float:left" class="thai_font_lable">Hình ảnh sản phẩm:</div>
                        <div style="width:80px;margin-top:7px;">                            
                            <a href="/admin/QLAnhSanPham.aspx?p_masanpham=<%=objSP.MaSanPham %>" target="_blank" >Xem ảnh</a>
                            
                        </div>                        
                    </div>
                    <%} %>
                </div>

                    
            </div>
                <div style="width:100%;text-align:right; float: right; display: block; position: fixed; z-index: 4000; bottom:0; background-color:#D7FFEB; left:0px">
                    <div style="float:left;padding-top: 0px;"><a href="/admin/home.aspx" ><img alt="" src="../img/home.png" title="Trang Chủ"/></a></div>
                    <div style="float:right;width:110px;">
                        <input type="submit" name="btn_Them" value="Thêm mới" onclick="return AddProduct();" id="btn_Them" class="btn btn-large btn-primary" style="margin:5px"/>            
                    </div>
                    <div style="float:right;width:68px;">
                        <input type="submit" name="btn_Sua" value="Sửa" onclick="return ModifyProduct();" id="btn_Sua" class="btn btn-large btn-primary" style="margin:5px"/>            
                    </div>
                    <div style="float:right;width:68px;">
                        <input type="submit" name="btn_Xoa" value="Xóa" onclick="return DeleteProduct();" id="btn_Xoa" class="btn btn-large btn-primary" style="margin:5px"/>            
                    </div>
                    <div style="float:right;width:125px;">
                        <input type="button" name="btn_Clear" value="Xóa biểu mẫu" onclick="clearAllInput();" id="btn_Clear" class="btn btn-large btn-primary" style="margin:5px"/>            
                    </div>
                </div>
                <div style="width:100%;text-align:left;padding-top:20px;height:80px">
                    &nbsp;
                </div>            

            <%if (objSP != null)
              { %>
                   <script type="text/javascript">
                       $('#div_spMoi').hide();
                   </script>
            <%} %>
            <%Session.Remove("page_QLSanPham_dataSP");
              Session.Remove("page_QLSanPham_MaSanPham_Moi");
              Session.Remove("page_QLSanPham_msgSucessFunc"); %>
        </form>
</body>
</html>
